-
Notifications
You must be signed in to change notification settings - Fork 9
/
PDFBuild+LyricsSection.swift
49 lines (42 loc) · 1.57 KB
/
PDFBuild+LyricsSection.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// PDFBuild+LyricsSection.swift
// Chord Provider
//
// © 2024 Nick Berendsen
//
import Foundation
import SwiftlyChordUtilities
extension PDFBuild {
// MARK: A PDF **lyrics section** element
/// A PDF **lyrics section** element
class LyricsSection: PDFElement {
/// The section with lyrics
let section: Song.Section
/// All the chords from the song
let chords: [ChordDefinition]
/// Init the **lyrics section** element
/// - Parameters:
/// - section: The section with lyrics
/// - chords: All the chords from the song
init(_ section: Song.Section, chords: [ChordDefinition]) {
self.section = section
self.chords = chords
}
/// Draw the **lyrics section** element
/// - Parameters:
/// - rect: The available rectangle
/// - calculationOnly: Bool if only the Bounding Rect should be calculated
/// - pageRect: The page size of the PDF document
func draw(rect: inout CGRect, calculationOnly: Bool, pageRect: CGRect) {
for line in section.lines {
if line.comment.isEmpty {
let line = Line(parts: line.parts, chords: chords)
line.draw(rect: &rect, calculationOnly: calculationOnly, pageRect: pageRect)
} else {
let comment = PDFBuild.Comment(line.comment).padding(6)
comment.draw(rect: &rect, calculationOnly: calculationOnly, pageRect: pageRect)
}
}
}
}
}